package com.androidx.p013lv.mine.activity;

import android.text.TextUtils;
import android.view.View;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.base.view.StatusControlLayout;
import com.androidx.p013lv.mine.C1207R;
import com.androidx.p013lv.mine.adapter.BuyHistoryAdapter;
import com.androidx.p013lv.mine.bean.BuyHistoryBean;
import com.androidx.p013lv.mine.databinding.ActivityBuyHistoryLayoutBinding;
import com.androidx.p013lv.mine.model.BuyHistoryModel;
import com.gyf.immersionbar.ImmersionBar;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import java.util.List;

/* renamed from: com.androidx.lv.mine.activity.BuyHistoryActivity */
public class BuyHistoryActivity extends BaseActivity<ActivityBuyHistoryLayoutBinding> implements OnRefreshLoadMoreListener, ItemClickListener {
    private BuyHistoryAdapter adapter;
    private BuyHistoryModel model;
    private int page = 1;

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((ActivityBuyHistoryLayoutBinding) this.binding).toolbar).init();
    }

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return C1207R.C1212layout.activity_buy_history_layout;
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        this.model = (BuyHistoryModel) new ViewModelProvider(this).get(BuyHistoryModel.class);
        ((ActivityBuyHistoryLayoutBinding) this.binding).setOnClick(new OnClick());
        BuyHistoryAdapter buyHistoryAdapter = new BuyHistoryAdapter();
        this.adapter = buyHistoryAdapter;
        buyHistoryAdapter.setItemListener(this);
        ((ActivityBuyHistoryLayoutBinding) this.binding).include.recycler.setPadding(0, UiUtils.dp2px(10), 0, 0);
        ((ActivityBuyHistoryLayoutBinding) this.binding).include.recycler.setLayoutManager(new LinearLayoutManager(this));
        ((ActivityBuyHistoryLayoutBinding) this.binding).include.recycler.setAdapter(this.adapter);
        ((ActivityBuyHistoryLayoutBinding) this.binding).include.refresh.setOnRefreshListener(this);
        ((ActivityBuyHistoryLayoutBinding) this.binding).include.refresh.setOnLoadMoreListener(this);
        ((ActivityBuyHistoryLayoutBinding) this.binding).include.statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.activity.BuyHistoryActivity.View$OnClickListenerC12211 */

            public void onClick(View view) {
                BuyHistoryActivity.this.page = 1;
                ((ActivityBuyHistoryLayoutBinding) BuyHistoryActivity.this.binding).setStatus(2);
                BuyHistoryActivity.this.model.getBuyHistory(BuyHistoryActivity.this.page);
            }
        });
        this.model.data().observe(this, new Observer<BaseRes<BuyHistoryBean>>() {
            /* class com.androidx.p013lv.mine.activity.BuyHistoryActivity.C12222 */

            public void onChanged(BaseRes<BuyHistoryBean> baseRes) {
                BuyHistoryActivity.this.hideLoading();
                if (baseRes.getCode() == 200) {
                    BuyHistoryBean data = baseRes.getData();
                    if (BuyHistoryActivity.this.page == 1) {
                        if (data == null || data.getData() == null || data.getData().size() == 0) {
                            ((ActivityBuyHistoryLayoutBinding) BuyHistoryActivity.this.binding).setStatus(4);
                            return;
                        }
                        List<BuyHistoryBean.DataBean> data2 = data.getData();
                        BuyHistoryActivity.this.adapter.setData(data2);
                        if (data2.size() < 30) {
                            ((ActivityBuyHistoryLayoutBinding) BuyHistoryActivity.this.binding).setStatusRefresh(2);
                        }
                    } else if (data == null || data.getData() == null || data.getData().size() == 0) {
                        ((ActivityBuyHistoryLayoutBinding) BuyHistoryActivity.this.binding).setStatusRefresh(2);
                    } else {
                        List<BuyHistoryBean.DataBean> data3 = data.getData();
                        BuyHistoryActivity.this.adapter.setDatasInEnd(data3);
                        if (data3.size() < 30) {
                            ((ActivityBuyHistoryLayoutBinding) BuyHistoryActivity.this.binding).setStatusRefresh(2);
                        }
                    }
                } else if (BuyHistoryActivity.this.page == 1) {
                    ((ActivityBuyHistoryLayoutBinding) BuyHistoryActivity.this.binding).setStatus(1);
                } else {
                    ToastUtils.getInstance().showWrong(baseRes.getMsg());
                }
            }
        });
        ((ActivityBuyHistoryLayoutBinding) this.binding).setStatus(2);
        this.model.getBuyHistory(this.page);
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        int i = this.page + 1;
        this.page = i;
        this.model.getBuyHistory(i);
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.page = 1;
        this.model.getBuyHistory(1);
    }

    public void hideLoading() {
        ((ActivityBuyHistoryLayoutBinding) this.binding).setStatus(0);
        ((ActivityBuyHistoryLayoutBinding) this.binding).setStatusRefresh(1);
    }

    public static void showStatusView(StatusControlLayout statusControlLayout, int i) {
        statusControlLayout.showStatusView(i);
    }

    public static void refreshStatus(SmartRefreshLayout smartRefreshLayout, int i) {
        if (i == 1) {
            smartRefreshLayout.finishLoadMore();
            smartRefreshLayout.finishRefresh();
        }
        if (i == 2) {
            smartRefreshLayout.finishLoadMoreWithNoMoreData();
        }
    }

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
        if (view.getId() != C1207R.C1210id.btn_copy_trade_no) {
            return;
        }
        if (TextUtils.isEmpty(((BuyHistoryBean.DataBean) this.adapter.getDataInPosition(i)).getTradeNo())) {
            ToastUtils.getInstance().showWrong("訂單號錯誤");
        } else if (!UiUtils.copyContentClipboard(((BuyHistoryBean.DataBean) this.adapter.getDataInPosition(i)).getTradeNo())) {
            ToastUtils.getInstance().showWeak("復制失敗");
        } else {
            ToastUtils.getInstance().showCorrect("復制成功");
        }
    }

    /* renamed from: com.androidx.lv.mine.activity.BuyHistoryActivity$OnClick */
    public class OnClick {
        public OnClick() {
        }

        public void btnBack() {
            BuyHistoryActivity.this.finish();
        }
    }

    /* access modifiers changed from: protected */
    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, com.androidx.p013lv.base.p015ui.BaseActivity
    public void onDestroy() {
        BuyHistoryModel buyHistoryModel = this.model;
        if (buyHistoryModel != null) {
            buyHistoryModel.cancelHttp();
        }
        super.onDestroy();
    }
}
